import '../helper/dioHelper.dart';

class XHSSKD {
  int Id;
  int TypeId;
  String Name;
  double KD1;
  double KD2;
  double Hours;
  String TZTM;
  String CreateTM;
  String Remark;

  XHSSKD(this.Id, this.TypeId, this.Name, this.KD1, this.KD2, this.Hours,
      this.TZTM, this.CreateTM, this.Remark);
  XHSSKD.fromJson(Map<String, dynamic> json)
      : Id = json["Id"],
        TypeId = json["TypeId"],
        Name = json["Name"],
        KD1 = json["KD1"],
        KD2 = json["KD2"],
        Hours = json["Hours"],
        TZTM = json["TZTM"],
        CreateTM = json["CreateTM"],
        Remark = json["Remark"];
  Map<String, dynamic> toJson() => {
        'Id': Id,
        'TypeId': TypeId,
        'Name': Name,
        'KD1': KD1,
        'KD2': KD2,
        'Hours': Hours,
        'TZTM': TZTM,
        'CreateTM': CreateTM,
        'Remark': Remark,
      };
  static Future<bool> Add(XHSSKD x1) async {
    var response = await DioHelper.Post("/XHSSKD/Add", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Update(XHSSKD x1) async {
    var response = await DioHelper.Post("/XHSSKD/Update", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Delete(XHSSKD x1) async {
    var st = x1.toJson();
    var response = await DioHelper.Post("/XHSSKD/Delete", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<XHSSKD?> Get(String where, dynamic data) async {
    var response = await DioHelper.Post("/XHSSKD/GetByWhere", {
      "Where": where,
      "obj": data,
    });

    if (response.statusCode == 200) return new XHSSKD.fromJson(response.data);
    return null;
  }

  static Future<List<XHSSKD>> GetList(
      String where, dynamic data, int pageIndex, int pageSize) async {
    var response = await DioHelper.Post("/XHSSKD/GetListByWhere", {
      "Where": where,
      "obj": data,
      "PageIndex": pageIndex,
      "PageSize": pageSize,
    });
    var list1 = <XHSSKD>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new XHSSKD.fromJson(x));
      }
    }
    return list1;
  }

  static Future<List<XHSSKD>> GetAllList() async {
    var response = await DioHelper.Get("/XHSSKD/GetAllList", {});
    var list1 = <XHSSKD>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new XHSSKD.fromJson(x));
      }
    }
    return list1;
  }
}
